﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using HROReporting.Controllers.ViewModels.StudentAccount;
using HROReporting.Infrastructure.Authentication;
using HROReporting.Infrastructure.CookieStorage;
using HROReporting.Services.Interfaces;
using HROReporting.Services.Messaging.StudentService;
using HROReporting.Services.ViewModels;
using HROReporting.Controllers.ViewModels.Vergader;
using HROReporting.Services.Messaging.SchoolLocatieService;

namespace HROReporting.Controllers.Controllers
{
    [Authorize]
    public class StudentController : BaseController
    {
        private readonly IStudentService _studentService;
        private readonly IFormsAuthentication _formsAuthentication;
        private readonly ISchoolLocatieService _schoolLocatieService;

        public StudentController(ICookieStorageService cookieStorageService,
                                 ISchoolLocatieService schoolLocatieService,
                                 IStudentService studentService,
                                 IFormsAuthentication formsAuthentication)
            : base (cookieStorageService)
        {
            _schoolLocatieService = schoolLocatieService;
            _studentService = studentService;
            _formsAuthentication = formsAuthentication;
        }

        [Authorize]
        public ActionResult Details()
        {
            GetStudentRequest studentRequest = new GetStudentRequest();
            studentRequest.StudentIdentityToken = _formsAuthentication.GetAuthenticationToken();

            GetStudentResponse response = _studentService.GetStudent(studentRequest);

            StudentDetailView studentDetailView = new StudentDetailView();
            studentDetailView.Student = response.Student;

            return View(studentDetailView);
        }

        [Authorize]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Details(StudentView studentView)
        {
            ModifyStudentRequest request = new ModifyStudentRequest();

            request.StudentIdentityToken = _formsAuthentication.GetAuthenticationToken();
            request.Email = studentView.Email;
            request.Studentnummer = studentView.Studentnummer;

            ModifyStudentResponse response = _studentService.ModifyStudent(request);

            StudentDetailView studentDetailView = new StudentDetailView();
            studentDetailView.Student = response.Student;

            return View(studentDetailView);
        }

        [Authorize]
        public ActionResult Reserveringen()
        {
            //VergaderDetailView vergaderDetailsView = new VergaderDetailView();

            //GetVergaderRuimteByRequest request = new GetVergaderRuimteByRequest();
            //request.SchoolLocatie = locatie;
            //request.VergaderRuimteCode = code;

            //GetVergaderRuimteByResponse response2 = _schoolLocatieService.GetVergaderRuimteBy(request);

            //vergaderDetailsView.VergaderRuimte = response2.VergaderRuimte;
            //vergaderDetailsView.VergaderRuimteCode = code;

            VergaderDetailView vergaderDetailsView = new VergaderDetailView();
            GetStudentRequest studentRequest = new GetStudentRequest();
            studentRequest.StudentIdentityToken = _formsAuthentication.GetAuthenticationToken();

            GetStudentResponse response = _studentService.GetStudent(studentRequest);


            StudentDetailView studentDetailView = new StudentDetailView();
            studentDetailView.Student = response.Student;

            return View(vergaderDetailsView);
        }
    }
}
